<!--
 * @Description: 树形权限组件
 * @Author: Liu Kunpeng
 * @Date: 2021-07-27 16:14:21
-->
<template>
    <div>
        <el-tree :data="getPermission"
            highlight-current
            show-checkbox
            accordion
            node-key="id"
            label="description"
            ref="tree"
            :props="ownProps"
            :default-expanded-keys="[1]"
            >
        </el-tree>
        
    </div>
</template>

<script>
export default {
    data() {
        return {
            ownProps:{
                label: 'description',
                children: 'children'
            },
        }
    },
    methods: {
        setCheckedKeys(arr){
            this.$refs.tree.setCheckedKeys(arr)
        },
        getCheckedNodes(){
           console.log(this.$refs.tree.getCheckedNodes())
           const checkedNodes = this.$refs.tree.getCheckedNodes()
           let checkedId = new Array()
           checkedNodes.forEach(e => {
               checkedId.push(e.id)
           });
           console.log(checkedId)
           return checkedId
        },
    },
    computed:{
        getPermission(){
            let treePermission = this.$store.state.user.treePermission
            if(treePermission.length === 0){
                this.$store.dispatch('user/getTreePermission')
            }
            return this.$store.state.user.treePermission
        }
    }
}
</script>

<style lang="less" scoped>
    
</style>